struct CollIntersect{
	Vector NewCenter;
	Vector IntersectPoint;
	Vector IntersectNormal;
	float Interval;
	ULONG TriangleIndex;
};

struct collision_data{
	Vector velocity;
	Vector velocity_normal;
	Vector base_point;
	bool isColliding;
	float nearest_distance;
	Vector intersect_point;
};

class Collision{
public:
	void collide_to_triangle(collision_data &data, Triangle &pTriangle);
	void check_collision(collision_data &data);
	bool point_in_triangle_3d_fast(Vector point, const Vector &t1, const Vector &t2, Vector const &t3);
	Vector collide_with_world(collision_data &data, Vector &pos, const Vector &Radius, Vector &eDeltaVelocity,int iterationCounter);
	void collide_and_slide(Vector &Center, const Vector &Radius, Vector &DeltaVelocity, bool enableGravity);
	bool SphereIntersectPoint(const Vector &Center, float Radius, const Vector &Velocity, const Vector &Point, float &tMax, Vector &CollisionNormal);
	bool SphereIntersectLineSegment(const Vector &Center, float Radius, const Vector &Velocity, const Vector &v1, const Vector &v2, float &tMax, Vector &CollisionNormal);
	bool SphereIntersectTriangle(const Vector &Center, float Radius, const Vector &Velocity,const Vector &t1, const Vector &t2, const Vector &t3, const Vector &triNormal, float &tMax, Vector &CollisionNormal);
	bool SphereIntersectPlane(const Vector &planeNormal,const Vector &v1,const Vector &Center,const Vector &Velocity,float Radius,float &tMax);
	bool RayIntersectPlane(Triangle &testTriangle,Vector *Origin,Vector *Direction,float *t, Vector &IntersectionPoint);
	bool PointInTriangle(Vector point, const Vector &t1, const Vector &t2, Vector const &t3);
	bool CollideEllipsoid(const Vector &Center, const Vector &Radius, const Vector &Velocity,Vector &NewCenter, Vector &IntegrationVelocity);
	bool EllipsoidIntersectScene(const Vector &Center,const Vector &Radius,const Vector &Velocity,CollIntersect Intersections[],ULONG &IntersectionCount);
	bool SolveCollision(float a, float b, float c, float &t);
	void test_edge(collision_data &data, const Vector &p1, const Vector &p2, float &vel_length_sq, Vector &collision_point, float &t, bool &found_collision);
	void test_point(collision_data &data, const Vector &p, float &vel_length_sq, Vector &collision_point, float &t, bool &found_collision);
	Collision();
	~Collision();
private:
	USHORT m_nMaxIntersections;
	USHORT m_nMaxIterations;
	CollIntersect *m_pIntersections;
	char* m_strCollisionType;
};